/**

 */
package Control;

import java.util.Enumeration;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Web.xml中全局参数的监视类<br>
 * 用户监视和获取Web.xml中的全局变量<br>
 * 在变量改变时通知CConfig，并修改全局参数<br>
 * 辅助实现网站数据库的热切换（开发中）<br>
 * @author qyfz45-user
 */
public class CListener implements ServletContextListener{
    /**
     * 
     * @param event 
     */
    public void contextInitialized(ServletContextEvent event){
       System.out.print("Listening");
        ServletContext   ctx   =   event.getServletContext(); 
        CConfig  cfg  =CConfig.getConfig(); 
        Enumeration  names   = ctx.getInitParameterNames(); 
       while(names.hasMoreElements()){ 
            String   key   =     (String)   names.nextElement(); 
            cfg.add(key,ctx.getInitParameter(key)); 
      }
        if(cfg.getProperties().get("Database").toString().equals("MongoDB"))
        {
            cfg.UpdateProperties("Database", "MongoDAL.MongodbFactory");
            
        }
        else if(cfg.getProperties().get("Database").toString().equals("SQLServer"))
        {
             cfg.UpdateProperties("Database", "SQLDAL.SQLFactory");
             
        }
} 
    /**
     * 
     * @param event 
     */
public void contextDestroyed(ServletContextEvent event){
 }
}



